package com.typy.www.tpay;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioGroup;

import com.hjm.bottomtabbar.BottomTabBar;
import com.typy.www.tpay.base.BaseFragmentActivity;
import com.typy.www.tpay.ui.fragment.FriendsFragment;
import com.typy.www.tpay.ui.fragment.HomeFragment;
import com.typy.www.tpay.ui.fragment.MineFragment;
import com.typy.www.tpay.constance.MessageEvent;
import com.typy.www.tpay.util.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;

/**
 * Created by 13799 on 2018/5/29.
 */

public class MainActivity extends BaseFragmentActivity{
    private BottomTabBar mBottomTabBar;

    public static void show(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getTitleBarResId() {
        return -1;
    }


    @Override
    protected int getContentResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        super.initView();
        EventBus.getDefault().register(this);
        initTab();
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void messageEventBus(MessageEvent msg){

    }

    //设置底部tab
    private void initTab(){
        mBottomTabBar = (BottomTabBar) findViewById(R.id.bottom_tab_bar);
        mBottomTabBar.init(getSupportFragmentManager(), 720, 1280)
                .setImgSize(50, 50)
                .setFontSize(12)
                .setTabPadding(10, 2, 5)
                .setChangeColor(Color.parseColor("#45ACF9"), Color.parseColor("#505050"))
                .addTabItem("首页", R.drawable.shouye_haoyou, R.drawable.shouye_haoyou, HomeFragment.class)
                .addTabItem("好友", R.drawable.shouye_haoyou, R.drawable.shouye_haoyou, FriendsFragment.class)
                .addTabItem("我的", R.drawable.shouye_haoyou, R.drawable.shouye_haoyou, MineFragment.class)
                .isShowDivider(true)
                .setDividerColor(getResources().getColor(R.color.divider_color))
                .setTabBarBackgroundColor(Color.parseColor("#00FF0000"))
                .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
                    @Override
                    public void onTabChange(int position, String name, View view) {
                        if (position == 1) mBottomTabBar.setSpot(1, false);
                    }
                })
                .setSpot(0, false)
                .setSpot(1, false)
                .setSpot(2, false)
                .setCurrentTab(0);
    }

    public void setTabIndex(int index){
        mBottomTabBar.setCurrentTab(index);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
